#include "../Headers/types.h"
#include "nameserversrv.h"

// Constructor
TOB::NameserverSRV::NameserverSRV() {
	config = new Config(CONFIG);
}


// Destructor
TOB::NameserverSRV::~NameserverSRV() {
	delete config;
}


// Handler
bool TOB::NameserverSRV::requestAddress(Server::Type server, TOB::Nameserver::IP &ipAddr) {
	std::string key;

	switch(server) {
	case Server::Authentication:
		key = "server-AN";
		break;

	case Server::Authorization:
		key = "server-AR";
		break;

	case Server::UserStorage:
		key = "server-US";
		break;

	case Server::UserManagement:
		key = "server-UM";
		break;

	case Server::Email:
		key = "server-EM";
		break;

	case Server::FileSharing:
		key = "server-FS";
		break;

	case Server::Calendar:
		key = "server-CL";
		break;

	case Server::ToDo:
		key = "server-TD";
		break;
	
	case Server::Directory:
		key = "server-DR";
		break;

	case Server::Time:
		key = "server-TM";
		break;

	case Server::WebServer:
		key = "server-WS";
		break;

	case Server::Chat:
		key = "server-CH";
		break;

	default:
		return false;
	}

	std::string &val = config->stringValue(key);
	if(!val.size()) return false;

  if(Nameserver::convertString(val, ipAddr) == Code::NS_CantConvert) { return false; }
	return true;
}
